$(document).ready(function(){
	$("#wechat_form").on("click",".index_submit",doIndexForm);
	//$("#queryFormId").on("click",".btn-add",showEditDialog);
	doGetCities();
	
});
function doGetCities(){
	var url="mobile/searchCity.do"
	var params;
	$.post(url,params,function(result){
		addCityOption(result.data);
	});
};
function addCityOption(list){
	for(var i in list){
		  $("#searchCity").append("<option id='"+list[i].id+"'>"+list[i].name+"</option>");
	}
	doGetAreas();//加载数据
};
//得到场馆城市id，发送请求，得到区信息
function doGetAreas(){

	var url="mobile/searchArea.do"
	var params={"parent_id":$("#searchCity option:selected").attr("id")};
	$.post(url,params,function(result){
		addAreaOption(result.data)
	});
}
//加载区信息
function addAreaOption(list){
	$("#searchArea").find("option").remove(); 
	/*var str3=$("#searchArea").childNodes
	if(str3){
	for(var j=str3.length-1;j>=0;j--){
		$("#searchArea").removeChild(str3[j]);
		}
	}*/
	for(var i in list){
		  $("#searchArea").append("<option id='"+list[i].id+"'>"+list[i].name+"</option>");
	}
}

//提交表单信息
function doIndexForm(){
	var areaId=$('#searchArea option:selected').attr("id");
	var address=$('#addressId').html();
	window.location.href="${basePath}/mobile/searchSite_list.do?id="+id"&address="+address;
	
}


function showEditDialog(){
	var title;
    var url="team/editUI.do"
	if($(this).hasClass("btn-add")){
		title="添加信息"
	}
	$("#modal-dialog .modal-body").load(url,function(){
		 $(".modal-title").html(title);
		 $("#modal-dialog").modal("show");
	});
}

function doGetObjects(){
	//1.url
	var url="team/doFindPageObjects.do"
	//2.params
	var params=getQueryFormData();
	var pageCurrent=$("#pageId").data("pageCurrent");
	if(pageCurrent){//true
		params.pageCurrent=pageCurrent;
	}else{
		params.pageCurrent=1;
	}
	console.log("pageCurrent="+pageCurrent);
	//3.ajax (post)                    
    $.post(url,params,function(result){
    	console.log(JSON.stringify(result));
    	if(result.state==1){//SUCCESS
    	//3.1 填充表格(setTableRows(result.data.list))
    	setTableRows(result.data.list)
    	//3.2 设置分页(setPagination(result.data.pageObject))
    	setPagination(result.data.pageObject);
    	}else{
    	  alert(result.message);
    	}
    });
}
/**获得查询表单中的数据*/
function getQueryFormData(){
	var params={//对象中的名字要与controller方法中的参数名相同
		"projectName":$("#searchNameId").val(),
		"valid":$("#searchValidId").val()
	}
	return params;
}
function setTableRows(list){
	//迭代list(此集合中现在存储的是多个map)
	var tds='<td><input type="checkbox" name="checkedItem" value="[id]"></td>'
	        +"<td>[name]</td>"
	        +"<td>[projectName]</td>"
	        +"<td>[valid]</td>"
	        +"<td>修改</td>";
	var tBody=$("#tbodyId");
	tBody.empty();
	for(var i in list){
		var tr=$("<tr></tr>");
		tr.append(
		tds.replace("[id]",list[i].id)
		   .replace("[name]",list[i].name)
		   .replace("[projectName]",list[i].projectName)
		   .replace("[valid]",list[i].valid?"启用":"禁用"));
	    tBody.append(tr);
	}
}




  












